#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *fp;
    if ((fp = fopen(".\\Prime.txt", "w")) == 0)
    {
        printf("Open file failed");
        return -1;
    }
    
    int n;
    printf("How much you want to printf:\n");
    scanf("%d", &n);

    long long num, factor, *prime;
    int i, j;

    if ((prime = (long long *)malloc(n * sizeof(long long))) == NULL)
    {
        printf("malloc error!\n");
        return -2;
    }
    prime[0] = 2;

    //printf("2,");
    fprintf(fp, "2,");

    for (i = 0, num = 2; i < n; num++)
    {
        for (j = 0; j <= i; j++)
        {
            if (num % prime[j] == 0)
            {
                break;
            }
            
        }
        if (j > i)
        {
            i++;
            prime[i] = num;
            //printf("%lld,", num);
            if (num % 2 != 0)
            {
                fprintf(fp, "%lld,", num);
            }
            
            if ((i + 1) % 50 == 0)
            {
                fprintf(fp, "\n");
            }
            
        }
        
    }
    
    fclose(fp);

    return 0;
}